﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService.Connect;
using System.Data.SqlClient;
using Model;
using System.Data;

namespace WebService.Datalayer
{
    public class DBTables
    {
        Database db = new Database();
        SqlParameter[] listParameter;

        /// <summary>
        /// SelectTablessAll
        /// </summary>
        /// <returns></returns>
        public DataSet SelectTablesAll()
        {
            return db.GetDataset("sp_SelectTablesAll");
        }

        /// <summary>
        /// SelectTablesByAndTableID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectTablesByAndTableID(Tables obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@TableID", obj.TableID),
            };
            return db.GetDataSetWithParameter("sp_SelectTablesByAndTableID", listParameter);
        }

        /// <summary>
        /// SelectTablesByAndRegionID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectTablesByAndRegionID(Tables obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@RegionID", obj.RegionID),
            };
            return db.GetDataSetWithParameter("sp_SelectTablesByAndRegionID", listParameter);
        }

        /// <summary>
        /// DeleteTables
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int DeleteTable(Tables obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@TableID", obj.TableID),
            };
            return db.ExcuteQueryWithParamater("sp_DeleteTable", listParameter);
        }

        /// <summary>
        /// InsertTable
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int InsertTable(Tables obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@TableID", obj.TableID),
                new SqlParameter("@TableName", obj.TableName),
                new SqlParameter("@RegionID", obj.RegionID),
                new SqlParameter("@Description", obj.Description),
                new SqlParameter("@IsBlank", obj.IsBlank),
                new SqlParameter("@IsDeleted", obj.IsDeleted),
            };
            return db.ExcuteQueryWithParamater("sp_InsertTable", listParameter);
        }

        /// <summary>
        /// UpdateTable
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int UpdateTable(Tables obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@TableID", obj.TableID),
                new SqlParameter("@TableName", obj.TableName),
                new SqlParameter("@RegionID", obj.RegionID),
                new SqlParameter("@Description", obj.Description),
                new SqlParameter("@IsBlank", obj.IsBlank),
                new SqlParameter("@IsDeleted", obj.IsDeleted),
            };
            return db.ExcuteQueryWithParamater("sp_UpdateTable", listParameter);
        }
    }
}